<?php
namespace Home\Controller\Goods;
use Home\Controller\Layout\LayoutController;
class DetailController extends LayoutController {
	public function index(){
		// var_dump(I('get.'));
		if(!empty($_GET['id'])){
			$data = M('g_goods')->where('id='.I('get.id'))->find();
			$pic = M('g_goods_pic')->select();
			foreach($pic as $k=>$v){
				if($v['gid']==I('get.id') && $v['goods_zpic']==1){
					$data['zpic']=$v['goods_pic'];
				}elseif($v['gid']==I('get.id') && $v['goods_zpic']==0){
					$data['pic'][]=$v['goods_pic'];
				}
			}
			$xiangguan = M('g_goods')->where('pinpai='.$data['pinpai'])->select();
			foreach($xiangguan as $k2=>&$v2){
				foreach($pic as $k1=>$v1){
					if($v1['gid']==$v2['id'] && $v1['goods_zpic']==1){
						$v2['zpic']=$v1['goods_pic'];
					}
				}
			}
			$x = [];
			if(count($xiangguan)>=4){
				$xiabiao = array_rand($xiangguan,'4');
				foreach($xiabiao as $k3=>$v3){
					$x[]=$xiangguan[$v3];
				}
			}else{
				$x = $xiangguan;
			}
			

			// foreach($xiangguan as $key=>$val){
			// 	if($val['id']>$data['id']){
			// 		var_dump($val);die;
			// 	}
			// }
			// var_dump($xiangguan);die;
		}
		if(empty($data)){
			echo '<script>window.location.href="'.U('home/goods/details/all').'"</script>';
			return ;
		}

		$data['price']=floor($data['goods_price']/0.8);
		$this->xiangguan=$x;
		$this->list=$data;
		$this->display();
	}
}